﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccess.Operate
{
    public class DA_Report_Change_AreaUnit_Inherit:SqlInteractionBase
    {
        public DataSet Search(string FormlyerExchangeDate, string FormlyerReportNO)
        {
            string sSql = "select * from t_Report_Change_AreaUnit where 1=1 ";
            if (FormlyerExchangeDate != "") sSql += "and Report_Change_AreaUnit_FormlyerExchangeDate='" + FormlyerExchangeDate+"' ";
            if (FormlyerReportNO != "") sSql += "and Report_Change_AreaUnit_FormlyerReportNO='" + FormlyerReportNO + "'";
            
            
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }

        #region 查询全部字典
        /// <summary>
        /// 查询全部字典
        /// </summary>
        /// <returns></returns>
        public DataSet FindLibrary()
        {

            string sSql = "select * from t_Dic_Report_Adjust";
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }
        #endregion

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <param name="audit">审核步骤</param>
        /// <returns></returns>
        public bool AuditByID(string id, string audit)
        {
            string sSql = "update t_Report_Change_AreaUnit set Report_Plan_Audit=" + audit + " where Report_Change_AreaUnit_ID='" + id + "'";
            return RunNoneSQL(sSql);
        }

    }
}
